using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public interface IGlobalIO {
	void UpdateIO();
}

/**
 * This is for non-time-sensitive IO
 * e.g. toggling character window
 * e.g. talking to NPCs
 */
class GlobalIO : MonoBehaviour {
	public GlobalAccess globals;
	
	private Dictionary<System.Type, IGlobalIO> elements = null;

	
	void Awake() {
		this.globals = new GlobalAccess();
		this.elements = new Dictionary<System.Type, IGlobalIO>();
		this.elements[typeof(RaycastIO)] = new RaycastIO();
		this.elements[typeof(PlayerIO)] = new PlayerIO();
	}
	
	void Start() {
		this.elements[typeof(GuiIO)] =
			(IGlobalIO)this.gameObject.AddComponent(typeof(GuiIO));
	}
	
	void Update() {
		/**
	 	* TODO: basically we want to skip the raycasts if we're clicking on a GUI
	 	* Right now, we don't have that
	 	*/
		foreach (IGlobalIO i in this.elements.Values) {
			if (i != null) {
				i.UpdateIO ();
			}
		}
	}
	
	public RaycastIO RaycastGet() {
		if (this.elements == null) {
			return null;
		}
		
		if (this.elements.ContainsKey (typeof(RaycastIO))) {
			return (RaycastIO)this.elements[typeof(RaycastIO)];
		} else {
			return null;
		}
	}
}